﻿namespace MyTRCP.Common.Models
{
    public class Rda1846sAgc : BitWalkableObj
    {
        public bool SmEnabled { get; set; }
        public byte SmStartNoiseL { get; set; }
        public byte SmAttenu { get; set; }
        public byte SmTime { get; set; }
        public byte SmChangeInterval { get; set; }
        public byte AgcChangeThd { get; set; }
        public Rda1846sAgc(byte[] data):base(data)
        {
        }

        public override BitWalker WriteToBitWalker(BitWalker bw)
        {
            return bw
                 .WriteBit(SmEnabled)
                 .WriteBits(SmStartNoiseL, 7)
                 .WriteBits(SmAttenu, 4)
                 .WriteBits(SmTime, 4)
                 .WriteBits(SmChangeInterval, 3)
                 .WriteBits(AgcChangeThd, 5);
        }

        public override BitWalker ReadFromBitWalker(BitWalker bw)
        {
            if (bw.ByteLen < 4)
                throw new ArgumentException("字节数组长度过小（4）", nameof(bw));
            SmEnabled = bw.ReadBit();
            SmStartNoiseL = (byte)bw.ReadBits(7);
            SmAttenu = (byte)bw.ReadBits(4);
            SmTime = (byte)bw.ReadBits(4);
            SmChangeInterval = (byte)bw.ReadBits(3);
            AgcChangeThd = (byte)bw.ReadBits(5);
            return bw;
        }
    }
}